// pages/album_issue/album_issue.js
var app = getApp()
Page({
  data:{},
  onLoad:function(o){
    if(wx.getStorageSync('album_info_s')){
      var album = wx.getStorageSync('album_info_s')
  //  console.log(album)
      this.setData({
        album:album
      })
    }
   //	this.Get_Album_Info(o.album_id)
  },

//接收表单数据并修改缓存
  formSubmit(e){

    var time = new Date()
    if(wx.getStorageSync('album_name_timestart') && time.getTime()-wx.getStorageSync('album_name_timestart') < 1000){
      return
    }
    wx.setStorageSync('album_name_timestart',time.getTime())

    if(!e.detail.value.album_name){
      wx.showToast({'title':'相册名不得为空！'})
      return
    }
    var t = this
    if(wx.getStorageSync('album_info_s')){
      var album = wx.getStorageSync('album_info_s')
      album.Album_Name = e.detail.value.album_name
      album.Album_Info = e.detail.value.album_info
      album.Album_Public = e.detail.value.album_public
      wx.setStorageSync('album_info_s',album)
      wx.redirectTo({url:'../album_add/album_add?album_id='+t.data.album_id})
    }else{
      var openid = wx.getStorageSync('openid')
      var album = new Object()
      album.Album_UserOpenid = openid
      album.Album_Name = e.detail.value.album_name
      album.Album_Info = e.detail.value.album_info
      album.Album_Public = e.detail.value.album_public

      wx.request({
        url:app.globalData.urls,
        data:{
          GetTypes:'Album_Add',
          Album_UserOpenid:openid,
          Album_Name:e.detail.value.album_name,
          Album_Info:e.detail.value.album_info,
          Album_Public:e.detail.value.album_public
        },
        success:function(res){
          if(res.data!='err'){
            album.Album_Id=res.data
            wx.setStorageSync('album_info_s',album)
            if(wx.getStorageSync('album_info_s')){
              wx.redirectTo({url:'../album_add/album_add'})
            }
          }
        }
      })
    }
  },

//获取相册信息
	Get_Album_Info(album_id){
		var t = this
		wx.request({
			url:app.globalData.urls,
			data:{
				'GetTypes':'Album_Get_One_Info',
				'album_id':album_id
			},
			success:function(res){
				t.setData({
					album_info:res.data
				})
			//	console.log(res.data)
			}
		})
	}

})